import json
import consumer
import producer
from loguru import logger
from perMTL import rumor

input_topic = "mindPlorer"
output_topic = "system"

def process_fake_detect(input:dict)->dict:
    return rumor.rumor_model(input)

process_dict = {
    "fakeDetect": process_fake_detect
}

def process(msg):
    # 数据处理
    value = msg.value
    input_data = json.loads(value['data'])
    output = process_dict[value['reqName']](input_data)

    
    value['data'] = json.dumps(output)
    # 发送数据
    kp = producer.Producer(output_topic)
    try:
        kp.asyn_producer_callback([value])
    except Exception as e:
        logger.exception(f'except error {e}')
    finally:
        kp.close_producer()

consumer.handle = process

if __name__ == '__main__':
    consumer.multi_consume(input_topic)